package com.wanmait.mpdemo.controller;


import com.wanmait.mpdemo.entity.QuestionType;
import com.wanmait.mpdemo.service.QuestionTypeService;
import com.wanmait.mpdemo.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wanmait
 * @since 2022-01-14
 */
@RestController
@RequestMapping("/manage/questionType")
@CrossOrigin//允许跨域请求
public class QuestionTypeController {
    @Resource
    private QuestionTypeService questionTypeService;
    @RequestMapping("list")
    public Result list(){
        return Result.success(questionTypeService.list());
    }

    @PostMapping("update")
    public Result update(@RequestBody QuestionType questionType){
        questionTypeService.updateById(questionType);
        return Result.success();
    }
    @PostMapping("insert")
    public Result insert(@RequestBody QuestionType questionType){
        questionTypeService.save(questionType);
        return Result.success("添加成功,id="+questionType.getId());
    }
    // /manage/questionType/findById?id=123
    // /manage/questionType/123
    //@GetMapping("findById")
    @GetMapping("{id:\\d+}")
    public Result findById(@PathVariable Integer id){
        return Result.success(questionTypeService.getById(id));
    }
/*    @GetMapping("delete")
    public Result delete(Integer id){
        questionTypeService.removeById(id);
        return Result.success();
    }*/

    @DeleteMapping("{id:\\d+}")
    public Result delete(@PathVariable Integer id){
        questionTypeService.removeById(id);
        return Result.success();
    }


}
